
<template>
    <uni-data-picker :modelValue="value" :map="{ text: 'mc', value: 'dm' }" :localdata="localdata" popup-title="请选择"
        @change="change" :clear-icon="false"></uni-data-picker>
</template>
<script setup lang="ts">
import { useDistStore } from '@/stores/modules/dist';
import { ref, watch } from 'vue';
const localdata = ref([] as any)
//避开uni官方组件值为空不回显列表的问题
const value = ref("null")
const props = defineProps({
    modelValue: {
        type: String,
    },
    zdlb: {
        type: String,
        required: true
    }
})
const emits = defineEmits(['update:modelValue']);

watch(() => props.modelValue, (newValue) => {
    if (newValue) {
        value.value = newValue
    }
})

if (props.zdlb) {
    useDistStore().getDictTree({ zdlb: props.zdlb }).then(result => {
        localdata.value = result
        if (props.modelValue) {
            value.value = props.modelValue
        }
    })
}
const change = ({ detail: { value } }: any) => {
    console.log(value[value.length - 1].value)
    emits('update:modelValue', value[value.length - 1].value)
}
</script>
<style lang="scss" scoped>

</style>
